package oss

import (
	"fmt"
	"net/url"
)

//GetService https://docs.aliyun.com/#/pub/oss/api-reference/service&GetService
func (o *OssAPI) GetService(prefix string, marker string, maxKeys int) (*ListAllMyBucketsResult, error) {
	if maxKeys > MaxKeySize {
		return nil, NewOssError(InvalidArgument, fmt.Sprintf("max key must <= 1000, given is too large %d", maxKeys))
	}

	resource := "/"

	v := url.Values{}
	if prefix != "" {
		v.Add("prefix", prefix)
	}

	if marker != "" {
		v.Add("marker", marker)
	}

	if maxKeys != 100 {
		v.Add("max-keys", fmt.Sprintf("%v", maxKeys))
	}

	result := ListAllMyBucketsResult{}
	err := o.httpGet(resource, v, nil, &result)
	if err != nil {
		return nil, err
	}

	return &result, nil
}
